﻿@{
        
        var action = UrlData[0].ToLower();
        
        Dictionary<string,string> c = new Dictionary<string,string>();
        c["Solicitor"]=UtilityManager.GetVal(Request["solicitor"]);
        c["CustomerClass"]=UtilityManager.GetVal(Request["custClass"]);
        c["Country"]=UtilityManager.GetVal(Request["country"]);
        c["City"]=UtilityManager.GetVal(Request["city"]);
        c["Pbank"]=UtilityManager.GetVal(Request["pbank"]);
        c["State"]=UtilityManager.GetVal(Request["state"]);
        c["Region"]=UtilityManager.GetVal(Request["region"]);
        var pbank =UtilityManager.GetVal(Request["pbank"]);
        
        
        var ccList = CashCardManager.ExtractData(c,action); 
        var cols = new []{"CashCardAppNo","NameOnCard","CashCardNo","PartnerBank","CashCardStatus","CardDelStatus","DelStatusDate"};
        var grid = new WebGrid(ccList,canSort:false,canPage:false,columnNames:cols,rowsPerPage:5,ajaxUpdateContainerId: "grid",ajaxUpdateCallback: "addCheck");
        var recCount=ccList.Count;
}
<script type="text/javascript">
      $(function(){
            
            addCheck();
           /* $("#download").click(function(){
                dlSelected("@action");
            });
            
            $("#print2pdf").click(function(){
                print2pdf();
            });
 
            
            $("#download").prop('disabled',true);
            $("#print2pdf").prop('disabled',true);*/
            
        });
        
         //maintain webgrid scroll position
     $(function(){
        $('th a, tfoot a').live('click', function(){
            $(this).attr('href', '#grid-anchor');
        });
    });
        
        
        function addCheck(){
              $("#download").click(function(){
                dlSelected("@action");
            });
            
            $("#print2pdf").click(function(){
                print2pdf();
            });
 
            
            $("#download").prop('disabled',true);
            $("#print2pdf").prop('disabled',true);
            
            var $chk = $('<input/>').attr({ type: 'checkbox', name:'chkAll', id: 'chkAll', title: "Select All"});
            $('th:last').html('Select All <br/>').append($chk);
            $('#chkAll').click(function(){
            
            if(@recCount>0){
                    $(':checkbox').attr('checked', $(this).is(':checked') ? true : false );
                    //$('#ccap').attr('checked', $(this).is(':checked') ? true : false );
                    $("#download").prop('disabled',$(this).is(':checked') ? false : true );
                    $("#print2pdf").prop('disabled',$(this).is(':checked') ? false : true );
                 }
            });
            
        
          $(':checkbox').not('#chkAll').click(function(){
               testCheck();
           });   
           
            
        }
      
   
        
     function testCheck() {
       
        //var isChecked = $('#ccap').attr('checked')?true:false;
    var isChecked = $("input[type=checkbox]:not('#chkAll')").is(':checked');
    var isCheckAll = $('#chkAll').is(':checked');
  
   
    
    
     if(isChecked){
         
             $('#chkAll').prop('checked', true);
             $("#download").prop('disabled',false);
             $("#print2pdf").prop('disabled',false);
            
        } else {
             $('#chkAll').prop('checked', false);
             $("#download").prop('disabled',true);
             $("#print2pdf").prop('disabled',true);
        }
        
        
       
        
    }
    
    function dlSelected(action){
        //var ccList = $("#cclist").serialize();
        //alert(ccList);
        
        $("#cclist").attr("action", "/CashCard/GenerateExcel/" + action);
        $("#cclist").submit();
        
         var ccList = $("#cclist").serialize();
        //regular expressiong to count number of occurance in a string
        var count = ccList.match(/ccappnos/g); 
        $("#totExt").empty();
        $("#totExt").html("Total Records Extracted:#"+count.length);
    }
    
    function print2pdf(){
        //$("#cclist").attr("action", "/CashCard/PrintToPDFAppFOrm/");
         $("#cclist").attr("action", "/CashCard/PrintCCAppForm/");
        $("#cclist").submit();
         var ccList = $("#cclist").serialize();
        //regular expressiong to count number of occurance in a string
        var count = ccList.match(/ccappnos/g); 
        $("#totExt").empty();
        $("#totExt").html("Total Records Extracted:#"+count.length);
    }
</script>
<style>
.fixedH{
    position:fixed;
}
</style>
<a name="grid-anchor"></a>
<fieldset>           
 
 <legend>Cash cards for @action</legend>
      <form   id="cclist">
    <input type="hidden" id="page"/>   
    <input type="hidden" name="pbank" value="@pbank"/>    
    <input type="hidden" id="printAll" value=""/>    
   
      <div id="buttons" >
        <p>
           <h3> <input type="button" id="download" value="download selected"/>
            <input type="button" id="print2pdf" value="print to pdf"/>
            <span id="totExt"></span></h3>
            
        </p>
       
        </div>  
         
<div id="grid">
  @functions{
                static IHtmlString ShowCCStatus(string status){
                    var s = RefDataManager.GetCashCardStatLkUpVal();
                    string cstat = string.Empty;
                    foreach(var cs in s){
                        if(cs.RefID.Equals(status)){
                            cstat=cs.RefDesc;
                        }
                    }
                    
                    return new HtmlString(cstat);
                }
                
                static IHtmlString ShowDelStatus(string del){
                    var d = RefDataManager.GetCardDelLkUpVal();
                    string cdel = string.Empty;
                    foreach(var cd in d){
                        if(cd.RefID.Equals(del)){
                            cdel=cd.RefDesc;
                        }
                    }
                    
                    return new HtmlString(cdel);
                }
                
                 static IHtmlString ShowDelStatDate(string delstatdate){
                      return delstatdate!="01-01-1900"?new HtmlString(delstatdate):new HtmlString("");
                } 
                
                
           }
  
      @grid.GetHtml(
               tableStyle:"webgrid",
               alternatingRowStyle:"webgrid-alternating-row",
               headerStyle:"ui-widget-header",
               fillEmptyRows:true,
               columns:grid.Columns(
                      grid.Column(
                        columnName:"NameOnCard",
                        header:"Name"
                      ),
                      grid.Column(
                         columnName:"CashCardNo",
                         header:"Card Number"
                      ),
                      grid.Column(
                         columnName:"PartnerBank",
                         header:"Partner Bank"
                      ),
                    
                      grid.Column(
                        columnName:"CashCardStatus",
                        header:"Status",
                        format:@<text>@ShowCCStatus(item.CashCardStatus.ToString())</text>
                      ),
                    
                      grid.Column(
                        columnName:"CardDelStatus",
                        header:"Delivery Status",
                         format:@<text>@ShowDelStatus(item.CardDelStatus.ToString())</text>
                      ),
                    
                      grid.Column(
                       columnName:"DelStatusDate",
                        header:"Delivery Status Date",
                        format:@<text>@ShowDelStatDate((item.DelStatusDate!=null)?item.DelStatusDate.ToString("MM-dd-yyyy"):null)</text>
                      ),
                      
                      grid.Column(header:"", format:@<input type="checkbox"  id="ccappnos" name="ccappnos" value="@item.CashCardAppNo"/>)
                      
               
              )
               
            )
        
  
       
        
        </form>
      
      </div>
    </fieldset>